//
//  API+ObjC.swift
//  TimeBoat
//
//  Created by bo wang on 2022/9/4.
//  Copyright © 2022 Time Boat. All rights reserved.
//

import Foundation

extension APIManager {
    
    typealias CompletionObjC = (_ suc: Bool, _ data: UndefinedModel?, _ error: String?) -> Void

    // 这是原始请求
    @discardableResult
    fileprivate
    func exampleRequest(_ p1: String,
                        _ p2: String,
                        completion: APINormalCompletion? = nil)
    -> APITASK? {
        var params = [String: Any]()
        params["p1"] = p1
        params["p2"] = p2
        return POST("example_api", params, completion)
    }
    
    // 这是暴露给ObjC调用的方法
    @objc func exampleRequestObjc(_ p1: String,
                                  _ p2: String,
                                  completion: CompletionObjC?) {
        exampleRequest(p1, p2) { result in
            completion?(result.suc, result.data, result.errDesc)
        }
    }
}
